#include "utils.h"
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>

std::string get_current_time()
{
    time_t now = time(nullptr);
    char buf[16];
    strftime(buf, sizeof(buf), "[%H:%M:%S]", localtime(&now));
    return std::string(buf);
}

std::string color_wrap(const std::string& msg, const std::string& color_code)
{
    return color_code + msg + Color::RESET;
}

void log_to_file(const std::string& msg)
{
    std::ofstream out("chat_log.txt", std::ios::app);
    if(out)
        out << msg << '\n';
    else
        std::cerr << "[log error] 无法打开日志文件 chat_log.txt\n";
}
